home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Include / d3dx9math.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-04  |  43.7 KB  |  1,390 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx9math.h
  6. //  Content:    D3DX math types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "d3dx9.h"
  11.  
  12. #ifndef __D3DX9MATH_H__
  13. #define __D3DX9MATH_H__
  14.  
  15. #include <math.h>
  16. #if _MSC_VER >= 1200
  17. #pragma warning(push)
  18. #endif
  19. #pragma warning(disable:4201) // anonymous unions warning
  20.  
  21.  
  22.  
  23. //===========================================================================
  24. //
  25. // General purpose utilities
  26. //
  27. //===========================================================================
  28. #define D3DX_PI    ((FLOAT)  3.141592654f)
  29. #define D3DX_1BYPI ((FLOAT)  0.318309886f)
  30.  
  31. #define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
  32. #define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))
  33.  
  34.  
  35.  
  36. //===========================================================================
  37. //
  38. // 16 bit floating point numbers
  39. //
  40. //===========================================================================
  41.  
  42. #define D3DX_16F_DIG          3                // # of decimal digits of precision
  43. #define D3DX_16F_EPSILON      4.8875809e-4f    // smallest such that 1.0 + epsilon != 1.0
  44. #define D3DX_16F_MANT_DIG     11               // # of bits in mantissa
  45. #define D3DX_16F_MAX          6.550400e+004    // max value
  46. #define D3DX_16F_MAX_10_EXP   4                // max decimal exponent
  47. #define D3DX_16F_MAX_EXP      15               // max binary exponent
  48. #define D3DX_16F_MIN          6.1035156e-5f    // min positive value
  49. #define D3DX_16F_MIN_10_EXP   (-4)             // min decimal exponent
  50. #define D3DX_16F_MIN_EXP      (-12)            // min binary exponent
  51. #define D3DX_16F_RADIX        2                // exponent radix
  52. #define D3DX_16F_ROUNDS       1                // addition rounding: near
  53.  
  54.  
  55. typedef struct D3DXFLOAT16
  56. {
  57. #ifdef __cplusplus
  58. public:
  59.     D3DXFLOAT16() {};
  60.     D3DXFLOAT16( FLOAT );
  61.     D3DXFLOAT16( CONST D3DXFLOAT16& );
  62.  
  63.     // casting
  64.     operator FLOAT ();
  65.  
  66.     // binary operators
  67.     BOOL operator == ( CONST D3DXFLOAT16& ) const;
  68.     BOOL operator != ( CONST D3DXFLOAT16& ) const;
  69.  
  70. protected:
  71. #endif //__cplusplus
  72.     WORD value;
  73. } D3DXFLOAT16, *LPD3DXFLOAT16;
  74.  
  75.  
  76.  
  77. //===========================================================================
  78. //
  79. // Vectors
  80. //
  81. //===========================================================================
  82.  
  83.  
  84. //--------------------------
  85. // 2D Vector
  86. //--------------------------
  87. typedef struct D3DXVECTOR2
  88. {
  89. #ifdef __cplusplus
  90. public:
  91.     D3DXVECTOR2() {};
  92.     D3DXVECTOR2( CONST FLOAT * );
  93.     D3DXVECTOR2( CONST D3DXFLOAT16 * );
  94.     D3DXVECTOR2( FLOAT x, FLOAT y );
  95.  
  96.     // casting
  97.     operator FLOAT* ();
  98.     operator CONST FLOAT* () const;
  99.  
  100.     // assignment operators
  101.     D3DXVECTOR2& operator += ( CONST D3DXVECTOR2& );
  102.     D3DXVECTOR2& operator -= ( CONST D3DXVECTOR2& );
  103.     D3DXVECTOR2& operator *= ( FLOAT );
  104.     D3DXVECTOR2& operator /= ( FLOAT );
  105.  
  106.     // unary operators
  107.     D3DXVECTOR2 operator + () const;
  108.     D3DXVECTOR2 operator - () const;
  109.  
  110.     // binary operators
  111.     D3DXVECTOR2 operator + ( CONST D3DXVECTOR2& ) const;
  112.     D3DXVECTOR2 operator - ( CONST D3DXVECTOR2& ) const;
  113.     D3DXVECTOR2 operator * ( FLOAT ) const;
  114.     D3DXVECTOR2 operator / ( FLOAT ) const;
  115.  
  116.     friend D3DXVECTOR2 operator * ( FLOAT, CONST D3DXVECTOR2& );
  117.  
  118.     BOOL operator == ( CONST D3DXVECTOR2& ) const;
  119.     BOOL operator != ( CONST D3DXVECTOR2& ) const;
  120.  
  121.  
  122. public:
  123. #endif //__cplusplus
  124.     FLOAT x, y;
  125. } D3DXVECTOR2, *LPD3DXVECTOR2;
  126.  
  127.  
  128.  
  129. //--------------------------
  130. // 2D Vector (16 bit)
  131. //--------------------------
  132.  
  133. typedef struct D3DXVECTOR2_16F
  134. {
  135. #ifdef __cplusplus
  136. public:
  137.     D3DXVECTOR2_16F() {};
  138.     D3DXVECTOR2_16F( CONST FLOAT * );
  139.     D3DXVECTOR2_16F( CONST D3DXFLOAT16 * );
  140.     D3DXVECTOR2_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y );
  141.  
  142.     // casting
  143.     operator D3DXFLOAT16* ();
  144.     operator CONST D3DXFLOAT16* () const;
  145.  
  146.     // binary operators
  147.     BOOL operator == ( CONST D3DXVECTOR2_16F& ) const;
  148.     BOOL operator != ( CONST D3DXVECTOR2_16F& ) const;
  149.  
  150. public:
  151. #endif //__cplusplus
  152.     D3DXFLOAT16 x, y;
  153.  
  154. } D3DXVECTOR2_16F, *LPD3DXVECTOR2_16F;
  155.  
  156.  
  157.  
  158. //--------------------------
  159. // 3D Vector
  160. //--------------------------
  161. #ifdef __cplusplus
  162. typedef struct D3DXVECTOR3 : public D3DVECTOR
  163. {
  164. public:
  165.     D3DXVECTOR3() {};
  166.     D3DXVECTOR3( CONST FLOAT * );
  167.     D3DXVECTOR3( CONST D3DVECTOR& );
  168.     D3DXVECTOR3( CONST D3DXFLOAT16 * );
  169.     D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z );
  170.  
  171.     // casting
  172.     operator FLOAT* ();
  173.     operator CONST FLOAT* () const;
  174.  
  175.     // assignment operators
  176.     D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& );
  177.     D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& );
  178.     D3DXVECTOR3& operator *= ( FLOAT );
  179.     D3DXVECTOR3& operator /= ( FLOAT );
  180.  
  181.     // unary operators
  182.     D3DXVECTOR3 operator + () const;
  183.     D3DXVECTOR3 operator - () const;
  184.  
  185.     // binary operators
  186.     D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const;
  187.     D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const;
  188.     D3DXVECTOR3 operator * ( FLOAT ) const;
  189.     D3DXVECTOR3 operator / ( FLOAT ) const;
  190.  
  191.     friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& );
  192.  
  193.     BOOL operator == ( CONST D3DXVECTOR3& ) const;
  194.     BOOL operator != ( CONST D3DXVECTOR3& ) const;
  195.  
  196. } D3DXVECTOR3, *LPD3DXVECTOR3;
  197.  
  198. #else //!__cplusplus
  199. typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
  200. #endif //!__cplusplus
  201.  
  202.  
  203.  
  204. //--------------------------
  205. // 3D Vector (16 bit)
  206. //--------------------------
  207. typedef struct D3DXVECTOR3_16F
  208. {
  209. #ifdef __cplusplus
  210. public:
  211.     D3DXVECTOR3_16F() {};
  212.     D3DXVECTOR3_16F( CONST FLOAT * );
  213.     D3DXVECTOR3_16F( CONST D3DVECTOR& );
  214.     D3DXVECTOR3_16F( CONST D3DXFLOAT16 * );
  215.     D3DXVECTOR3_16F( CONST D3DXFLOAT16 &x, CONST D3DXFLOAT16 &y, CONST D3DXFLOAT16 &z );
  216.  
  217.     // casting
  218.     operator D3DXFLOAT16* ();
  219.     operator CONST D3DXFLOAT16* () const;
  220.  
  221.     // binary operators
  222.     BOOL operator == ( CONST D3DXVECTOR3_16F& ) const;
  223.     BOOL operator != ( CONST D3DXVECTOR3_16F& ) const;
  224.  
  225. public:
  226. #endif //__cplusplus
  227.     D3DXFLOAT16 x, y, z;
  228.  
  229. } D3DXVECTOR3_16F, *LPD3DXVECTOR3_16F;
  230.  
  231.  
  232.  
  233. //--------------------------
  234. // 4D Vector
  235. //--------------------------
  236. typedef struct D3DXVECTOR4
  237. {
  238. #ifdef __cplusplus
  239. public:
  240.     D3DXVECTOR4() {};
  241.     D3DXVECTOR4( CONST FLOAT* );
  242.     D3DXVECTOR4( CONST D3DXFLOAT16 * );
  243.     D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  244.  
  245.     // casting
  246.     operator FLOAT* ();
  247.     operator CONST FLOAT* () const;
  248.  
  249.     // assignment operators
  250.     D3DXVECTOR4& operator += ( CONST D3DXVECTOR4& );
  251.     D3DXVECTOR4& operator -= ( CONST D3DXVECTOR4& );
  252.     D3DXVECTOR4& operator *= ( FLOAT );
  253.     D3DXVECTOR4& operator /= ( FLOAT );
  254.  
  255.     // unary operators
  256.     D3DXVECTOR4 operator + () const;
  257.     D3DXVECTOR4 operator - () const;
  258.  
  259.     // binary operators
  260.     D3DXVECTOR4 operator + ( CONST D3DXVECTOR4& ) const;
  261.     D3DXVECTOR4 operator - ( CONST D3DXVECTOR4& ) const;
  262.     D3DXVECTOR4 operator * ( FLOAT ) const;
  263.     D3DXVECTOR4 operator / ( FLOAT ) const;
  264.  
  265.     friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& );
  266.  
  267.     BOOL operator == ( CONST D3DXVECTOR4& ) const;
  268.     BOOL operator != ( CONST D3DXVECTOR4& ) const;
  269.  
  270. public:
  271. #endif //__cplusplus
  272.     FLOAT x, y, z, w;
  273. } D3DXVECTOR4, *LPD3DXVECTOR4;
  274.  
  275.  
  276. //--------------------------
  277. // 4D Vector (16 bit)
  278. //--------------------------
  279. typedef struct D3DXVECTOR4_16F
  280. {
  281. #ifdef __cplusplus
  282. public:
  283.     D3DXVECTOR4_16F() {};
  284.     D3DXVECTOR4_16F( CONST FLOAT * );
  285.     D3DXVECTOR4_16F( CONST D3DXFLOAT16 * );
  286.     D3DXVECTOR4_16F( CONST D3DXFLOAT16& x, CONST D3DXFLOAT16& y, CONST D3DXFLOAT16& z, CONST D3DXFLOAT16& w );
  287.  
  288.     // casting
  289.     operator D3DXFLOAT16* ();
  290.     operator CONST D3DXFLOAT16* () const;
  291.  
  292.     // binary operators
  293.     BOOL operator == ( CONST D3DXVECTOR4_16F& ) const;
  294.     BOOL operator != ( CONST D3DXVECTOR4_16F& ) const;
  295.  
  296. public:
  297. #endif //__cplusplus
  298.     D3DXFLOAT16 x, y, z, w;
  299.  
  300. } D3DXVECTOR4_16F, *LPD3DXVECTOR4_16F;
  301.  
  302.  
  303.  
  304. //===========================================================================
  305. //
  306. // Matrices
  307. //
  308. //===========================================================================
  309. #ifdef __cplusplus
  310. typedef struct D3DXMATRIX : public D3DMATRIX
  311. {
  312. public:
  313.     D3DXMATRIX() {};
  314.     D3DXMATRIX( CONST FLOAT * );
  315.     D3DXMATRIX( CONST D3DMATRIX& );
  316.     D3DXMATRIX( CONST D3DXFLOAT16 * );
  317.     D3DXMATRIX( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  318.                 FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  319.                 FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  320.                 FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
  321.  
  322.  
  323.     // access grants
  324.     FLOAT& operator () ( UINT Row, UINT Col );
  325.     FLOAT  operator () ( UINT Row, UINT Col ) const;
  326.  
  327.     // casting operators
  328.     operator FLOAT* ();
  329.     operator CONST FLOAT* () const;
  330.  
  331.     // assignment operators
  332.     D3DXMATRIX& operator *= ( CONST D3DXMATRIX& );
  333.     D3DXMATRIX& operator += ( CONST D3DXMATRIX& );
  334.     D3DXMATRIX& operator -= ( CONST D3DXMATRIX& );
  335.     D3DXMATRIX& operator *= ( FLOAT );
  336.     D3DXMATRIX& operator /= ( FLOAT );
  337.  
  338.     // unary operators
  339.     D3DXMATRIX operator + () const;
  340.     D3DXMATRIX operator - () const;
  341.  
  342.     // binary operators
  343.     D3DXMATRIX operator * ( CONST D3DXMATRIX& ) const;
  344.     D3DXMATRIX operator + ( CONST D3DXMATRIX& ) const;
  345.     D3DXMATRIX operator - ( CONST D3DXMATRIX& ) const;
  346.     D3DXMATRIX operator * ( FLOAT ) const;
  347.     D3DXMATRIX operator / ( FLOAT ) const;
  348.  
  349.     friend D3DXMATRIX operator * ( FLOAT, CONST D3DXMATRIX& );
  350.  
  351.     BOOL operator == ( CONST D3DXMATRIX& ) const;
  352.     BOOL operator != ( CONST D3DXMATRIX& ) const;
  353.  
  354. } D3DXMATRIX, *LPD3DXMATRIX;
  355.  
  356. #else //!__cplusplus
  357. typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
  358. #endif //!__cplusplus
  359.  
  360.  
  361. //---------------------------------------------------------------------------
  362. // Aligned Matrices
  363. //
  364. // This class helps keep matrices 16-byte aligned as preferred by P4 cpus.
  365. // It aligns matrices on the stack and on the heap or in global scope.
  366. // It does this using __declspec(align(16)) which works on VC7 and on VC 6
  367. // with the processor pack. Unfortunately there is no way to detect the 
  368. // latter so this is turned on only on VC7. On other compilers this is the
  369. // the same as D3DXMATRIX.
  370. //
  371. // Using this class on a compiler that does not actually do the alignment
  372. // can be dangerous since it will not expose bugs that ignore alignment.
  373. // E.g if an object of this class in inside a struct or class, and some code
  374. // memcopys data in it assuming tight packing. This could break on a compiler
  375. // that eventually start aligning the matrix.
  376. //---------------------------------------------------------------------------
  377. #ifdef __cplusplus
  378. typedef struct _D3DXMATRIXA16 : public D3DXMATRIX
  379. {
  380.     _D3DXMATRIXA16() {}
  381.     _D3DXMATRIXA16( CONST FLOAT * );
  382.     _D3DXMATRIXA16( CONST D3DMATRIX& );
  383.     _D3DXMATRIXA16( CONST D3DXFLOAT16 * );
  384.     _D3DXMATRIXA16( FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14,
  385.                     FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24,
  386.                     FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34,
  387.                     FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 );
  388.  
  389.     // new operators
  390.     void* operator new   ( size_t );
  391.     void* operator new[] ( size_t );
  392.  
  393.     // delete operators
  394.     void operator delete   ( void* );   // These are NOT virtual; Do not 
  395.     void operator delete[] ( void* );   // cast to D3DXMATRIX and delete.
  396.     
  397.     // assignment operators
  398.     _D3DXMATRIXA16& operator = ( CONST D3DXMATRIX& );
  399.  
  400. } _D3DXMATRIXA16;
  401.  
  402. #else //!__cplusplus
  403. typedef D3DXMATRIX  _D3DXMATRIXA16;
  404. #endif //!__cplusplus
  405.  
  406.  
  407.  
  408. #if _MSC_VER >= 1300  // VC7
  409. #define D3DX_ALIGN16 __declspec(align(16))
  410. #else
  411. #define D3DX_ALIGN16  // Earlier compiler may not understand this, do nothing.
  412. #endif
  413.  
  414. typedef D3DX_ALIGN16 _D3DXMATRIXA16 D3DXMATRIXA16, *LPD3DXMATRIXA16;
  415.  
  416.  
  417.  
  418. //===========================================================================
  419. //
  420. //    Quaternions
  421. //
  422. //===========================================================================
  423. typedef struct D3DXQUATERNION
  424. {
  425. #ifdef __cplusplus
  426. public:
  427.     D3DXQUATERNION() {}
  428.     D3DXQUATERNION( CONST FLOAT * );
  429.     D3DXQUATERNION( CONST D3DXFLOAT16 * );
  430.     D3DXQUATERNION( FLOAT x, FLOAT y, FLOAT z, FLOAT w );
  431.  
  432.     // casting
  433.     operator FLOAT* ();
  434.     operator CONST FLOAT* () const;
  435.  
  436.     // assignment operators
  437.     D3DXQUATERNION& operator += ( CONST D3DXQUATERNION& );
  438.     D3DXQUATERNION& operator -= ( CONST D3DXQUATERNION& );
  439.     D3DXQUATERNION& operator *= ( CONST D3DXQUATERNION& );
  440.     D3DXQUATERNION& operator *= ( FLOAT );
  441.     D3DXQUATERNION& operator /= ( FLOAT );
  442.  
  443.     // unary operators
  444.     D3DXQUATERNION  operator + () const;
  445.     D3DXQUATERNION  operator - () const;
  446.  
  447.     // binary operators
  448.     D3DXQUATERNION operator + ( CONST D3DXQUATERNION& ) const;
  449.     D3DXQUATERNION operator - ( CONST D3DXQUATERNION& ) const;
  450.     D3DXQUATERNION operator * ( CONST D3DXQUATERNION& ) const;
  451.     D3DXQUATERNION operator * ( FLOAT ) const;
  452.     D3DXQUATERNION operator / ( FLOAT ) const;
  453.  
  454.     friend D3DXQUATERNION operator * (FLOAT, CONST D3DXQUATERNION& );
  455.  
  456.     BOOL operator == ( CONST D3DXQUATERNION& ) const;
  457.     BOOL operator != ( CONST D3DXQUATERNION& ) const;
  458.  
  459. #endif //__cplusplus
  460.     FLOAT x, y, z, w;
  461. } D3DXQUATERNION, *LPD3DXQUATERNION;
  462.  
  463.  
  464. //===========================================================================
  465. //
  466. // Planes
  467. //
  468. //===========================================================================
  469. typedef struct D3DXPLANE
  470. {
  471. #ifdef __cplusplus
  472. public:
  473.     D3DXPLANE() {}
  474.     D3DXPLANE( CONST FLOAT* );
  475.     D3DXPLANE( CONST D3DXFLOAT16* );
  476.     D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d );
  477.  
  478.     // casting
  479.     operator FLOAT* ();
  480.     operator CONST FLOAT* () const;
  481.  
  482.     // unary operators
  483.     D3DXPLANE operator + () const;
  484.     D3DXPLANE operator - () const;
  485.  
  486.     // binary operators
  487.     BOOL operator == ( CONST D3DXPLANE& ) const;
  488.     BOOL operator != ( CONST D3DXPLANE& ) const;
  489.  
  490. #endif //__cplusplus
  491.     FLOAT a, b, c, d;
  492. } D3DXPLANE, *LPD3DXPLANE;
  493.  
  494.  
  495. //===========================================================================
  496. //
  497. // Colors
  498. //
  499. //===========================================================================
  500.  
  501. typedef struct D3DXCOLOR
  502. {
  503. #ifdef __cplusplus
  504. public:
  505.     D3DXCOLOR() {}
  506.     D3DXCOLOR( DWORD argb );
  507.     D3DXCOLOR( CONST FLOAT * );
  508.     D3DXCOLOR( CONST D3DXFLOAT16 * );
  509.     D3DXCOLOR( CONST D3DCOLORVALUE& );
  510.     D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
  511.  
  512.     // casting
  513.     operator DWORD () const;
  514.  
  515.     operator FLOAT* ();
  516.     operator CONST FLOAT* () const;
  517.  
  518.     operator D3DCOLORVALUE* ();
  519.     operator CONST D3DCOLORVALUE* () const;
  520.  
  521.     operator D3DCOLORVALUE& ();
  522.     operator CONST D3DCOLORVALUE& () const;
  523.  
  524.     // assignment operators
  525.     D3DXCOLOR& operator += ( CONST D3DXCOLOR& );
  526.     D3DXCOLOR& operator -= ( CONST D3DXCOLOR& );
  527.     D3DXCOLOR& operator *= ( FLOAT );
  528.     D3DXCOLOR& operator /= ( FLOAT );
  529.  
  530.     // unary operators
  531.     D3DXCOLOR operator + () const;
  532.     D3DXCOLOR operator - () const;
  533.  
  534.     // binary operators
  535.     D3DXCOLOR operator + ( CONST D3DXCOLOR& ) const;
  536.     D3DXCOLOR operator - ( CONST D3DXCOLOR& ) const;
  537.     D3DXCOLOR operator * ( FLOAT ) const;
  538.     D3DXCOLOR operator / ( FLOAT ) const;
  539.  
  540.     friend D3DXCOLOR operator * (FLOAT, CONST D3DXCOLOR& );
  541.  
  542.     BOOL operator == ( CONST D3DXCOLOR& ) const;
  543.     BOOL operator != ( CONST D3DXCOLOR& ) const;
  544.  
  545. #endif //__cplusplus
  546.     FLOAT r, g, b, a;
  547. } D3DXCOLOR, *LPD3DXCOLOR;
  548.  
  549.  
  550.  
  551. //===========================================================================
  552. //
  553. // D3DX math functions:
  554. //
  555. // NOTE:
  556. //  * All these functions can take the same object as in and out parameters.
  557. //
  558. //  * Out parameters are typically also returned as return values, so that
  559. //    the output of one function may be used as a parameter to another.
  560. //
  561. //===========================================================================
  562.  
  563. //--------------------------
  564. // Float16
  565. //--------------------------
  566.  
  567. // non-inline
  568. #ifdef __cplusplus
  569. extern "C" {
  570. #endif
  571.  
  572. // Converts an array 32-bit floats to 16-bit floats
  573. D3DXFLOAT16* WINAPI D3DXFloat32To16Array
  574.     ( D3DXFLOAT16 *pOut, CONST FLOAT *pIn, UINT n );
  575.  
  576. // Converts an array 16-bit floats to 32-bit floats
  577. FLOAT* WINAPI D3DXFloat16To32Array
  578.     ( FLOAT *pOut, CONST D3DXFLOAT16 *pIn, UINT n );
  579.  
  580. #ifdef __cplusplus
  581. }
  582. #endif
  583.  
  584.  
  585. //--------------------------
  586. // 2D Vector
  587. //--------------------------
  588.  
  589. // inline
  590.  
  591. FLOAT D3DXVec2Length
  592.     ( CONST D3DXVECTOR2 *pV );
  593.  
  594. FLOAT D3DXVec2LengthSq
  595.     ( CONST D3DXVECTOR2 *pV );
  596.  
  597. FLOAT D3DXVec2Dot
  598.     ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  599.  
  600. // Z component of ((x1,y1,0) cross (x2,y2,0))
  601. FLOAT D3DXVec2CCW
  602.     ( CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  603.  
  604. D3DXVECTOR2* D3DXVec2Add
  605.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  606.  
  607. D3DXVECTOR2* D3DXVec2Subtract
  608.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  609.  
  610. // Minimize each component.  x = min(x1, x2), y = min(y1, y2)
  611. D3DXVECTOR2* D3DXVec2Minimize
  612.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  613.  
  614. // Maximize each component.  x = max(x1, x2), y = max(y1, y2)
  615. D3DXVECTOR2* D3DXVec2Maximize
  616.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2 );
  617.  
  618. D3DXVECTOR2* D3DXVec2Scale
  619.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, FLOAT s );
  620.  
  621. // Linear interpolation. V1 + s(V2-V1)
  622. D3DXVECTOR2* D3DXVec2Lerp
  623.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  624.       FLOAT s );
  625.  
  626. // non-inline
  627. #ifdef __cplusplus
  628. extern "C" {
  629. #endif
  630.  
  631. D3DXVECTOR2* WINAPI D3DXVec2Normalize
  632.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV );
  633.  
  634. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  635. // and position V2, tangent T2 (when s == 1).
  636. D3DXVECTOR2* WINAPI D3DXVec2Hermite
  637.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pT1,
  638.       CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pT2, FLOAT s );
  639.  
  640. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  641. D3DXVECTOR2* WINAPI D3DXVec2CatmullRom
  642.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV0, CONST D3DXVECTOR2 *pV1,
  643.       CONST D3DXVECTOR2 *pV2, CONST D3DXVECTOR2 *pV3, FLOAT s );
  644.  
  645. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  646. D3DXVECTOR2* WINAPI D3DXVec2BaryCentric
  647.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV1, CONST D3DXVECTOR2 *pV2,
  648.       CONST D3DXVECTOR2 *pV3, FLOAT f, FLOAT g);
  649.  
  650. // Transform (x, y, 0, 1) by matrix.
  651. D3DXVECTOR4* WINAPI D3DXVec2Transform
  652.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  653.  
  654. // Transform (x, y, 0, 1) by matrix, project result back into w=1.
  655. D3DXVECTOR2* WINAPI D3DXVec2TransformCoord
  656.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  657.  
  658. // Transform (x, y, 0, 0) by matrix.
  659. D3DXVECTOR2* WINAPI D3DXVec2TransformNormal
  660.     ( D3DXVECTOR2 *pOut, CONST D3DXVECTOR2 *pV, CONST D3DXMATRIX *pM );
  661.      
  662. // Transform Array (x, y, 0, 1) by matrix.
  663. D3DXVECTOR4* WINAPI D3DXVec2TransformArray
  664.     ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n);
  665.  
  666. // Transform Array (x, y, 0, 1) by matrix, project result back into w=1.
  667. D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray
  668.     ( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  669.  
  670. // Transform Array (x, y, 0, 0) by matrix.
  671. D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray
  672.     ( D3DXVECTOR2 *pOut, UINT OutStride, CONST D3DXVECTOR2 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  673.     
  674.     
  675.  
  676. #ifdef __cplusplus
  677. }
  678. #endif
  679.  
  680.  
  681. //--------------------------
  682. // 3D Vector
  683. //--------------------------
  684.  
  685. // inline
  686.  
  687. FLOAT D3DXVec3Length
  688.     ( CONST D3DXVECTOR3 *pV );
  689.  
  690. FLOAT D3DXVec3LengthSq
  691.     ( CONST D3DXVECTOR3 *pV );
  692.  
  693. FLOAT D3DXVec3Dot
  694.     ( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  695.  
  696. D3DXVECTOR3* D3DXVec3Cross
  697.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  698.  
  699. D3DXVECTOR3* D3DXVec3Add
  700.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  701.  
  702. D3DXVECTOR3* D3DXVec3Subtract
  703.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  704.  
  705. // Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
  706. D3DXVECTOR3* D3DXVec3Minimize
  707.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  708.  
  709. // Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
  710. D3DXVECTOR3* D3DXVec3Maximize
  711.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 );
  712.  
  713. D3DXVECTOR3* D3DXVec3Scale
  714.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s);
  715.  
  716. // Linear interpolation. V1 + s(V2-V1)
  717. D3DXVECTOR3* D3DXVec3Lerp
  718.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  719.       FLOAT s );
  720.  
  721. // non-inline
  722. #ifdef __cplusplus
  723. extern "C" {
  724. #endif
  725.  
  726. D3DXVECTOR3* WINAPI D3DXVec3Normalize
  727.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV );
  728.  
  729. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  730. // and position V2, tangent T2 (when s == 1).
  731. D3DXVECTOR3* WINAPI D3DXVec3Hermite
  732.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pT1,
  733.       CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pT2, FLOAT s );
  734.  
  735. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  736. D3DXVECTOR3* WINAPI D3DXVec3CatmullRom
  737.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV0, CONST D3DXVECTOR3 *pV1,
  738.       CONST D3DXVECTOR3 *pV2, CONST D3DXVECTOR3 *pV3, FLOAT s );
  739.  
  740. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  741. D3DXVECTOR3* WINAPI D3DXVec3BaryCentric
  742.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  743.       CONST D3DXVECTOR3 *pV3, FLOAT f, FLOAT g);
  744.  
  745. // Transform (x, y, z, 1) by matrix.
  746. D3DXVECTOR4* WINAPI D3DXVec3Transform
  747.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  748.  
  749. // Transform (x, y, z, 1) by matrix, project result back into w=1.
  750. D3DXVECTOR3* WINAPI D3DXVec3TransformCoord
  751.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  752.  
  753. // Transform (x, y, z, 0) by matrix.  If you transforming a normal by a 
  754. // non-affine matrix, the matrix you pass to this function should be the 
  755. // transpose of the inverse of the matrix you would use to transform a coord.
  756. D3DXVECTOR3* WINAPI D3DXVec3TransformNormal
  757.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  758.     
  759.     
  760. // Transform Array (x, y, z, 1) by matrix. 
  761. D3DXVECTOR4* WINAPI D3DXVec3TransformArray
  762.     ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  763.  
  764. // Transform Array (x, y, z, 1) by matrix, project result back into w=1.
  765. D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray
  766.     ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  767.  
  768. // Transform (x, y, z, 0) by matrix.  If you transforming a normal by a 
  769. // non-affine matrix, the matrix you pass to this function should be the 
  770. // transpose of the inverse of the matrix you would use to transform a coord.
  771. D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray
  772.     ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  773.  
  774. // Project vector from object space into screen space
  775. D3DXVECTOR3* WINAPI D3DXVec3Project
  776.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DVIEWPORT9 *pViewport,
  777.       CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
  778.  
  779. // Project vector from screen space into object space
  780. D3DXVECTOR3* WINAPI D3DXVec3Unproject
  781.     ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DVIEWPORT9 *pViewport,
  782.       CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld);
  783.       
  784. // Project vector Array from object space into screen space
  785. D3DXVECTOR3* WINAPI D3DXVec3ProjectArray
  786.     ( D3DXVECTOR3 *pOut, UINT OutStride,CONST D3DXVECTOR3 *pV, UINT VStride,CONST D3DVIEWPORT9 *pViewport,
  787.       CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
  788.  
  789. // Project vector Array from screen space into object space
  790. D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray
  791.     ( D3DXVECTOR3 *pOut, UINT OutStride, CONST D3DXVECTOR3 *pV, UINT VStride, CONST D3DVIEWPORT9 *pViewport,
  792.       CONST D3DXMATRIX *pProjection, CONST D3DXMATRIX *pView, CONST D3DXMATRIX *pWorld, UINT n);
  793.  
  794.  
  795. #ifdef __cplusplus
  796. }
  797. #endif
  798.  
  799.  
  800.  
  801. //--------------------------
  802. // 4D Vector
  803. //--------------------------
  804.  
  805. // inline
  806.  
  807. FLOAT D3DXVec4Length
  808.     ( CONST D3DXVECTOR4 *pV );
  809.  
  810. FLOAT D3DXVec4LengthSq
  811.     ( CONST D3DXVECTOR4 *pV );
  812.  
  813. FLOAT D3DXVec4Dot
  814.     ( CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2 );
  815.  
  816. D3DXVECTOR4* D3DXVec4Add
  817.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  818.  
  819. D3DXVECTOR4* D3DXVec4Subtract
  820.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  821.  
  822. // Minimize each component.  x = min(x1, x2), y = min(y1, y2), ...
  823. D3DXVECTOR4* D3DXVec4Minimize
  824.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  825.  
  826. // Maximize each component.  x = max(x1, x2), y = max(y1, y2), ...
  827. D3DXVECTOR4* D3DXVec4Maximize
  828.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2);
  829.  
  830. D3DXVECTOR4* D3DXVec4Scale
  831.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, FLOAT s);
  832.  
  833. // Linear interpolation. V1 + s(V2-V1)
  834. D3DXVECTOR4* D3DXVec4Lerp
  835.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  836.       FLOAT s );
  837.  
  838. // non-inline
  839. #ifdef __cplusplus
  840. extern "C" {
  841. #endif
  842.  
  843. // Cross-product in 4 dimensions.
  844. D3DXVECTOR4* WINAPI D3DXVec4Cross
  845.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  846.       CONST D3DXVECTOR4 *pV3);
  847.  
  848. D3DXVECTOR4* WINAPI D3DXVec4Normalize
  849.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
  850.  
  851. // Hermite interpolation between position V1, tangent T1 (when s == 0)
  852. // and position V2, tangent T2 (when s == 1).
  853. D3DXVECTOR4* WINAPI D3DXVec4Hermite
  854.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pT1,
  855.       CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pT2, FLOAT s );
  856.  
  857. // CatmullRom interpolation between V1 (when s == 0) and V2 (when s == 1)
  858. D3DXVECTOR4* WINAPI D3DXVec4CatmullRom
  859.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV0, CONST D3DXVECTOR4 *pV1,
  860.       CONST D3DXVECTOR4 *pV2, CONST D3DXVECTOR4 *pV3, FLOAT s );
  861.  
  862. // Barycentric coordinates.  V1 + f(V2-V1) + g(V3-V1)
  863. D3DXVECTOR4* WINAPI D3DXVec4BaryCentric
  864.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV1, CONST D3DXVECTOR4 *pV2,
  865.       CONST D3DXVECTOR4 *pV3, FLOAT f, FLOAT g);
  866.  
  867. // Transform vector by matrix.
  868. D3DXVECTOR4* WINAPI D3DXVec4Transform
  869.     ( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
  870.     
  871. // Transform vector array by matrix.
  872. D3DXVECTOR4* WINAPI D3DXVec4TransformArray
  873.     ( D3DXVECTOR4 *pOut, UINT OutStride, CONST D3DXVECTOR4 *pV, UINT VStride, CONST D3DXMATRIX *pM, UINT n );
  874.  
  875. #ifdef __cplusplus
  876. }
  877. #endif
  878.  
  879.  
  880. //--------------------------
  881. // 4D Matrix
  882. //--------------------------
  883.  
  884. // inline
  885.  
  886. D3DXMATRIX* D3DXMatrixIdentity
  887.     ( D3DXMATRIX *pOut );
  888.  
  889. BOOL D3DXMatrixIsIdentity
  890.     ( CONST D3DXMATRIX *pM );
  891.  
  892.  
  893. // non-inline
  894. #ifdef __cplusplus
  895. extern "C" {
  896. #endif
  897.  
  898. FLOAT WINAPI D3DXMatrixDeterminant
  899.     ( CONST D3DXMATRIX *pM );
  900.  
  901. D3DXMATRIX* WINAPI D3DXMatrixTranspose
  902.     ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
  903.  
  904. // Matrix multiplication.  The result represents the transformation M2
  905. // followed by the transformation M1.  (Out = M1 * M2)
  906. D3DXMATRIX* WINAPI D3DXMatrixMultiply
  907.     ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  908.  
  909. // Matrix multiplication, followed by a transpose. (Out = T(M1 * M2))
  910. D3DXMATRIX* WINAPI D3DXMatrixMultiplyTranspose
  911.     ( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  912.  
  913. // Calculate inverse of matrix.  Inversion my fail, in which case NULL will
  914. // be returned.  The determinant of pM is also returned it pfDeterminant
  915. // is non-NULL.
  916. D3DXMATRIX* WINAPI D3DXMatrixInverse
  917.     ( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
  918.  
  919. // Build a matrix which scales by (sx, sy, sz)
  920. D3DXMATRIX* WINAPI D3DXMatrixScaling
  921.     ( D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz );
  922.  
  923. // Build a matrix which translates by (x, y, z)
  924. D3DXMATRIX* WINAPI D3DXMatrixTranslation
  925.     ( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  926.  
  927. // Build a matrix which rotates around the X axis
  928. D3DXMATRIX* WINAPI D3DXMatrixRotationX
  929.     ( D3DXMATRIX *pOut, FLOAT Angle );
  930.  
  931. // Build a matrix which rotates around the Y axis
  932. D3DXMATRIX* WINAPI D3DXMatrixRotationY
  933.     ( D3DXMATRIX *pOut, FLOAT Angle );
  934.  
  935. // Build a matrix which rotates around the Z axis
  936. D3DXMATRIX* WINAPI D3DXMatrixRotationZ
  937.     ( D3DXMATRIX *pOut, FLOAT Angle );
  938.  
  939. // Build a matrix which rotates around an arbitrary axis
  940. D3DXMATRIX* WINAPI D3DXMatrixRotationAxis
  941.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
  942.  
  943. // Build a matrix from a quaternion
  944. D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion
  945.     ( D3DXMATRIX *pOut, CONST D3DXQUATERNION *pQ);
  946.  
  947. // Yaw around the Y axis, a pitch around the X axis,
  948. // and a roll around the Z axis.
  949. D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll
  950.     ( D3DXMATRIX *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
  951.  
  952.  
  953. // Build transformation matrix.  NULL arguments are treated as identity.
  954. // Mout = Msc-1 * Msr-1 * Ms * Msr * Msc * Mrc-1 * Mr * Mrc * Mt
  955. D3DXMATRIX* WINAPI D3DXMatrixTransformation
  956.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pScalingCenter,
  957.       CONST D3DXQUATERNION *pScalingRotation, CONST D3DXVECTOR3 *pScaling,
  958.       CONST D3DXVECTOR3 *pRotationCenter, CONST D3DXQUATERNION *pRotation,
  959.       CONST D3DXVECTOR3 *pTranslation);
  960.  
  961. // Build affine transformation matrix.  NULL arguments are treated as identity.
  962. // Mout = Ms * Mrc-1 * Mr * Mrc * Mt
  963. D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation
  964.     ( D3DXMATRIX *pOut, FLOAT Scaling, CONST D3DXVECTOR3 *pRotationCenter,
  965.       CONST D3DXQUATERNION *pRotation, CONST D3DXVECTOR3 *pTranslation);
  966.  
  967. // Build a lookat matrix. (right-handed)
  968. D3DXMATRIX* WINAPI D3DXMatrixLookAtRH
  969.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
  970.       CONST D3DXVECTOR3 *pUp );
  971.  
  972. // Build a lookat matrix. (left-handed)
  973. D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
  974.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR3 *pEye, CONST D3DXVECTOR3 *pAt,
  975.       CONST D3DXVECTOR3 *pUp );
  976.  
  977. // Build a perspective projection matrix. (right-handed)
  978. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveRH
  979.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  980.  
  981. // Build a perspective projection matrix. (left-handed)
  982. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveLH
  983.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  984.  
  985. // Build a perspective projection matrix. (right-handed)
  986. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovRH
  987.     ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
  988.  
  989. // Build a perspective projection matrix. (left-handed)
  990. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveFovLH
  991.     ( D3DXMATRIX *pOut, FLOAT fovy, FLOAT Aspect, FLOAT zn, FLOAT zf );
  992.  
  993. // Build a perspective projection matrix. (right-handed)
  994. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterRH
  995.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  996.       FLOAT zf );
  997.  
  998. // Build a perspective projection matrix. (left-handed)
  999. D3DXMATRIX* WINAPI D3DXMatrixPerspectiveOffCenterLH
  1000.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  1001.       FLOAT zf );
  1002.  
  1003. // Build an ortho projection matrix. (right-handed)
  1004. D3DXMATRIX* WINAPI D3DXMatrixOrthoRH
  1005.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  1006.  
  1007. // Build an ortho projection matrix. (left-handed)
  1008. D3DXMATRIX* WINAPI D3DXMatrixOrthoLH
  1009.     ( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  1010.  
  1011. // Build an ortho projection matrix. (right-handed)
  1012. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterRH
  1013.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  1014.       FLOAT zf );
  1015.  
  1016. // Build an ortho projection matrix. (left-handed)
  1017. D3DXMATRIX* WINAPI D3DXMatrixOrthoOffCenterLH
  1018.     ( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,
  1019.       FLOAT zf );
  1020.  
  1021. // Build a matrix which flattens geometry into a plane, as if casting
  1022. // a shadow from a light.
  1023. D3DXMATRIX* WINAPI D3DXMatrixShadow
  1024.     ( D3DXMATRIX *pOut, CONST D3DXVECTOR4 *pLight,
  1025.       CONST D3DXPLANE *pPlane );
  1026.  
  1027. // Build a matrix which reflects the coordinate system about a plane
  1028. D3DXMATRIX* WINAPI D3DXMatrixReflect
  1029.     ( D3DXMATRIX *pOut, CONST D3DXPLANE *pPlane );
  1030.  
  1031. #ifdef __cplusplus
  1032. }
  1033. #endif
  1034.  
  1035.  
  1036. //--------------------------
  1037. // Quaternion
  1038. //--------------------------
  1039.  
  1040. // inline
  1041.  
  1042. FLOAT D3DXQuaternionLength
  1043.     ( CONST D3DXQUATERNION *pQ );
  1044.  
  1045. // Length squared, or "norm"
  1046. FLOAT D3DXQuaternionLengthSq
  1047.     ( CONST D3DXQUATERNION *pQ );
  1048.  
  1049. FLOAT D3DXQuaternionDot
  1050.     ( CONST D3DXQUATERNION *pQ1, CONST D3DXQUATERNION *pQ2 );
  1051.  
  1052. // (0, 0, 0, 1)
  1053. D3DXQUATERNION* D3DXQuaternionIdentity
  1054.     ( D3DXQUATERNION *pOut );
  1055.  
  1056. BOOL D3DXQuaternionIsIdentity
  1057.     ( CONST D3DXQUATERNION *pQ );
  1058.  
  1059. // (-x, -y, -z, w)
  1060. D3DXQUATERNION* D3DXQuaternionConjugate
  1061.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  1062.  
  1063.  
  1064. // non-inline
  1065. #ifdef __cplusplus
  1066. extern "C" {
  1067. #endif
  1068.  
  1069. // Compute a quaternin's axis and angle of rotation. Expects unit quaternions.
  1070. void WINAPI D3DXQuaternionToAxisAngle
  1071.     ( CONST D3DXQUATERNION *pQ, D3DXVECTOR3 *pAxis, FLOAT *pAngle );
  1072.  
  1073. // Build a quaternion from a rotation matrix.
  1074. D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix
  1075.     ( D3DXQUATERNION *pOut, CONST D3DXMATRIX *pM);
  1076.  
  1077. // Rotation about arbitrary axis.
  1078. D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis
  1079.     ( D3DXQUATERNION *pOut, CONST D3DXVECTOR3 *pV, FLOAT Angle );
  1080.  
  1081. // Yaw around the Y axis, a pitch around the X axis,
  1082. // and a roll around the Z axis.
  1083. D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll
  1084.     ( D3DXQUATERNION *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );
  1085.  
  1086. // Quaternion multiplication.  The result represents the rotation Q2
  1087. // followed by the rotation Q1.  (Out = Q2 * Q1)
  1088. D3DXQUATERNION* WINAPI D3DXQuaternionMultiply
  1089.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  1090.       CONST D3DXQUATERNION *pQ2 );
  1091.  
  1092. D3DXQUATERNION* WINAPI D3DXQuaternionNormalize
  1093.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  1094.  
  1095. // Conjugate and re-norm
  1096. D3DXQUATERNION* WINAPI D3DXQuaternionInverse
  1097.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  1098.  
  1099. // Expects unit quaternions.
  1100. // if q = (cos(theta), sin(theta) * v); ln(q) = (0, theta * v)
  1101. D3DXQUATERNION* WINAPI D3DXQuaternionLn
  1102.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  1103.  
  1104. // Expects pure quaternions. (w == 0)  w is ignored in calculation.
  1105. // if q = (0, theta * v); exp(q) = (cos(theta), sin(theta) * v)
  1106. D3DXQUATERNION* WINAPI D3DXQuaternionExp
  1107.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ );
  1108.       
  1109. // Spherical linear interpolation between Q1 (t == 0) and Q2 (t == 1).
  1110. // Expects unit quaternions.
  1111. D3DXQUATERNION* WINAPI D3DXQuaternionSlerp
  1112.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  1113.       CONST D3DXQUATERNION *pQ2, FLOAT t );
  1114.  
  1115. // Spherical quadrangle interpolation.
  1116. // Slerp(Slerp(Q1, C, t), Slerp(A, B, t), 2t(1-t))
  1117. D3DXQUATERNION* WINAPI D3DXQuaternionSquad
  1118.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  1119.       CONST D3DXQUATERNION *pA, CONST D3DXQUATERNION *pB,
  1120.       CONST D3DXQUATERNION *pC, FLOAT t );
  1121.  
  1122. // Setup control points for spherical quadrangle interpolation
  1123. // from Q1 to Q2.  The control points are chosen in such a way 
  1124. // to ensure the continuity of tangents with adjacent segments.
  1125. void WINAPI D3DXQuaternionSquadSetup
  1126.     ( D3DXQUATERNION *pAOut, D3DXQUATERNION *pBOut, D3DXQUATERNION *pCOut,
  1127.       CONST D3DXQUATERNION *pQ0, CONST D3DXQUATERNION *pQ1, 
  1128.       CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3 );
  1129.  
  1130. // Barycentric interpolation.
  1131. // Slerp(Slerp(Q1, Q2, f+g), Slerp(Q1, Q3, f+g), g/(f+g))
  1132. D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric
  1133.     ( D3DXQUATERNION *pOut, CONST D3DXQUATERNION *pQ1,
  1134.       CONST D3DXQUATERNION *pQ2, CONST D3DXQUATERNION *pQ3,
  1135.       FLOAT f, FLOAT g );
  1136.  
  1137. #ifdef __cplusplus
  1138. }
  1139. #endif
  1140.  
  1141.  
  1142. //--------------------------
  1143. // Plane
  1144. //--------------------------
  1145.  
  1146. // inline
  1147.  
  1148. // ax + by + cz + dw
  1149. FLOAT D3DXPlaneDot
  1150.     ( CONST D3DXPLANE *pP, CONST D3DXVECTOR4 *pV);
  1151.  
  1152. // ax + by + cz + d
  1153. FLOAT D3DXPlaneDotCoord
  1154.     ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
  1155.  
  1156. // ax + by + cz
  1157. FLOAT D3DXPlaneDotNormal
  1158.     ( CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV);
  1159.  
  1160. // non-inline
  1161. #ifdef __cplusplus
  1162. extern "C" {
  1163. #endif
  1164.  
  1165. // Normalize plane (so that |a,b,c| == 1)
  1166. D3DXPLANE* WINAPI D3DXPlaneNormalize
  1167.     ( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
  1168.  
  1169. // Find the intersection between a plane and a line.  If the line is
  1170. // parallel to the plane, NULL is returned.
  1171. D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine
  1172.     ( D3DXVECTOR3 *pOut, CONST D3DXPLANE *pP, CONST D3DXVECTOR3 *pV1,
  1173.       CONST D3DXVECTOR3 *pV2);
  1174.  
  1175. // Construct a plane from a point and a normal
  1176. D3DXPLANE* WINAPI D3DXPlaneFromPointNormal
  1177.     ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pPoint, CONST D3DXVECTOR3 *pNormal);
  1178.  
  1179. // Construct a plane from 3 points
  1180. D3DXPLANE* WINAPI D3DXPlaneFromPoints
  1181.     ( D3DXPLANE *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2,
  1182.       CONST D3DXVECTOR3 *pV3);
  1183.  
  1184. // Transform a plane by a matrix.  The vector (a,b,c) must be normal.
  1185. // M should be the inverse transpose of the transformation desired.
  1186. D3DXPLANE* WINAPI D3DXPlaneTransform
  1187.     ( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
  1188.     
  1189. // Transform an array of planes by a matrix.  The vectors (a,b,c) must be normal.
  1190. // M should be the inverse transpose of the transformation desired.
  1191. D3DXPLANE* WINAPI D3DXPlaneTransformArray
  1192.     ( D3DXPLANE *pOut, UINT OutStride, CONST D3DXPLANE *pP, UINT PStride, CONST D3DXMATRIX *pM, UINT n );
  1193.  
  1194. #ifdef __cplusplus
  1195. }
  1196. #endif
  1197.  
  1198.  
  1199. //--------------------------
  1200. // Color
  1201. //--------------------------
  1202.  
  1203. // inline
  1204.  
  1205. // (1-r, 1-g, 1-b, a)
  1206. D3DXCOLOR* D3DXColorNegative
  1207.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC);
  1208.  
  1209. D3DXCOLOR* D3DXColorAdd
  1210.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  1211.  
  1212. D3DXCOLOR* D3DXColorSubtract
  1213.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  1214.  
  1215. D3DXCOLOR* D3DXColorScale
  1216.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
  1217.  
  1218. // (r1*r2, g1*g2, b1*b2, a1*a2)
  1219. D3DXCOLOR* D3DXColorModulate
  1220.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2);
  1221.  
  1222. // Linear interpolation of r,g,b, and a. C1 + s(C2-C1)
  1223. D3DXCOLOR* D3DXColorLerp
  1224.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC1, CONST D3DXCOLOR *pC2, FLOAT s);
  1225.  
  1226. // non-inline
  1227. #ifdef __cplusplus
  1228. extern "C" {
  1229. #endif
  1230.  
  1231. // Interpolate r,g,b between desaturated color and color.
  1232. // DesaturatedColor + s(Color - DesaturatedColor)
  1233. D3DXCOLOR* WINAPI D3DXColorAdjustSaturation
  1234.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT s);
  1235.  
  1236. // Interpolate r,g,b between 50% grey and color.  Grey + s(Color - Grey)
  1237. D3DXCOLOR* WINAPI D3DXColorAdjustContrast
  1238.     (D3DXCOLOR *pOut, CONST D3DXCOLOR *pC, FLOAT c);
  1239.  
  1240. #ifdef __cplusplus
  1241. }
  1242. #endif
  1243.  
  1244.  
  1245.  
  1246.  
  1247. //--------------------------
  1248. // Misc
  1249. //--------------------------
  1250.  
  1251. #ifdef __cplusplus
  1252. extern "C" {
  1253. #endif
  1254.  
  1255. // Calculate Fresnel term given the cosine of theta (likely obtained by
  1256. // taking the dot of two normals), and the refraction index of the material.
  1257. FLOAT WINAPI D3DXFresnelTerm
  1258.     (FLOAT CosTheta, FLOAT RefractionIndex);     
  1259.  
  1260. #ifdef __cplusplus
  1261. }
  1262. #endif
  1263.  
  1264.  
  1265.  
  1266. //===========================================================================
  1267. //
  1268. //    Matrix Stack
  1269. //
  1270. //===========================================================================
  1271.  
  1272. typedef interface ID3DXMatrixStack ID3DXMatrixStack;
  1273. typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
  1274.  
  1275. // {E3357330-CC5E-11d2-A434-00A0C90629A8}
  1276. DEFINE_GUID( IID_ID3DXMatrixStack,
  1277. 0xe3357330, 0xcc5e, 0x11d2, 0xa4, 0x34, 0x0, 0xa0, 0xc9, 0x6, 0x29, 0xa8);
  1278.  
  1279.  
  1280. #undef INTERFACE
  1281. #define INTERFACE ID3DXMatrixStack
  1282.  
  1283. DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
  1284. {
  1285.     //
  1286.     // IUnknown methods
  1287.     //
  1288.     STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  1289.     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
  1290.     STDMETHOD_(ULONG,Release)(THIS) PURE;
  1291.  
  1292.     //
  1293.     // ID3DXMatrixStack methods
  1294.     //
  1295.  
  1296.     // Pops the top of the stack, returns the current top
  1297.     // *after* popping the top.
  1298.     STDMETHOD(Pop)(THIS) PURE;
  1299.  
  1300.     // Pushes the stack by one, duplicating the current matrix.
  1301.     STDMETHOD(Push)(THIS) PURE;
  1302.  
  1303.     // Loads identity in the current matrix.
  1304.     STDMETHOD(LoadIdentity)(THIS) PURE;
  1305.  
  1306.     // Loads the given matrix into the current matrix
  1307.     STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1308.  
  1309.     // Right-Multiplies the given matrix to the current matrix.
  1310.     // (transformation is about the current world origin)
  1311.     STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1312.  
  1313.     // Left-Multiplies the given matrix to the current matrix
  1314.     // (transformation is about the local origin of the object)
  1315.     STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
  1316.  
  1317.     // Right multiply the current matrix with the computed rotation
  1318.     // matrix, counterclockwise about the given axis with the given angle.
  1319.     // (rotation is about the current world origin)
  1320.     STDMETHOD(RotateAxis)
  1321.         (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
  1322.  
  1323.     // Left multiply the current matrix with the computed rotation
  1324.     // matrix, counterclockwise about the given axis with the given angle.
  1325.     // (rotation is about the local origin of the object)
  1326.     STDMETHOD(RotateAxisLocal)
  1327.         (THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
  1328.  
  1329.     // Right multiply the current matrix with the computed rotation
  1330.     // matrix. All angles are counterclockwise. (rotation is about the
  1331.     // current world origin)
  1332.  
  1333.     // The rotation is composed of a yaw around the Y axis, a pitch around
  1334.     // the X axis, and a roll around the Z axis.
  1335.     STDMETHOD(RotateYawPitchRoll)
  1336.         (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
  1337.  
  1338.     // Left multiply the current matrix with the computed rotation
  1339.     // matrix. All angles are counterclockwise. (rotation is about the
  1340.     // local origin of the object)
  1341.  
  1342.     // The rotation is composed of a yaw around the Y axis, a pitch around
  1343.     // the X axis, and a roll around the Z axis.
  1344.     STDMETHOD(RotateYawPitchRollLocal)
  1345.         (THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
  1346.  
  1347.     // Right multiply the current matrix with the computed scale
  1348.     // matrix. (transformation is about the current world origin)
  1349.     STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1350.  
  1351.     // Left multiply the current matrix with the computed scale
  1352.     // matrix. (transformation is about the local origin of the object)
  1353.     STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1354.  
  1355.     // Right multiply the current matrix with the computed translation
  1356.     // matrix. (transformation is about the current world origin)
  1357.     STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
  1358.  
  1359.     // Left multiply the current matrix with the computed translation
  1360.     // matrix. (transformation is about the local origin of the object)
  1361.     STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
  1362.  
  1363.     // Obtain the current matrix at the top of the stack
  1364.     STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
  1365. };
  1366.  
  1367. #ifdef __cplusplus
  1368. extern "C" {
  1369. #endif
  1370.  
  1371. HRESULT WINAPI 
  1372.     D3DXCreateMatrixStack( 
  1373.         DWORD               Flags, 
  1374.         LPD3DXMATRIXSTACK*  ppStack);
  1375.  
  1376. #ifdef __cplusplus
  1377. }
  1378. #endif
  1379.  
  1380. #include "d3dx9math.inl"
  1381.  
  1382. #if _MSC_VER >= 1200
  1383. #pragma warning(pop)
  1384. #else
  1385. #pragma warning(default:4201)
  1386. #endif
  1387.  
  1388. #endif // __D3DX9MATH_H__
  1389.  
  1390.